<?php

namespace application\model;

use application\model\BaseModel as BaseModel;
use application\entity\db\CpFunction;

class CpFunctionModel extends BaseModel {

    public function __construct() {
        parent::__construct(CpFunction::class);
    }

    /**
     * Chi tiết quyền theo uri
     * @param type $uri
     * @return type
     */
    public function getByUri($uri) {
        $cri = new \core\entity\Criteria();
        $cri->andKey("uri")->is($uri);
        $query = new \core\entity\Query($cri);
        return $this->ifindOne($query);
    }

    /**
     * Danh sách chức năng theo Parent id
     * @param type $parent
     * @return type
     */
    public function getByParent($parent) {
        $cri = new \core\entity\Criteria();
        $cri->andKey("Parent")->is($parent);
        $sort = new \core\entity\Sort(\core\entity\Sort::ASC, "positon");
        $query = new \core\entity\Query($cri);
        $query->withSort($sort);
        return $this->ifind($query);
    }

    /**
     * Đếm số quyền theo Parent id
     * @param type $parent
     * @return type
     */
    public function countByGroupId($groupId) {
        $cri = new \core\entity\Criteria();
        $cri->andKey("groupId")->is($groupId);
        return $this->icount($cri);
    }

}
